﻿using DLUProject.Domain;
using DLUProject.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class KTX_Home : BaseUserControl
{
    public ModuleInstanceExtension moduleInstance { get; set; }
    public IServices<ThongBao> _thongBao { get; set; }
    public IServices<TinTuc> _serviceTinTuc{ get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        Page.Title = "Trang chủ";
        if (!IsPostBack)
        {
            List<ModuleInstance> modules = moduleInstance.GetByModulePosition(ModulePosition.SlideShow);
            foreach (var item in modules)
            {
                BaseUserControl userControlX = (BaseUserControl)LoadControl(item.Module.Path);

                if (userControlX != null)
                {
                    userControlX.ModuleID = item.ModuleInstanceID.ToString();
                    userControlX.Title = item.Title;
                    userControlX.Params = item.Params;
                    userControlX.ShowHide = item.IsActive;
                    userControlX.State = item.State;
                    PlaceHolderSlideShow.Controls.Add(userControlX);
                }
            }
            List<ModuleInstance> modulesLeft = moduleInstance.GetByModulePosition(ModulePosition.Left);
            foreach (var item in modulesLeft)
            {
                BaseUserControl userControlX = (BaseUserControl)LoadControl(item.Module.Path);

                if (userControlX != null)
                {
                    userControlX.ModuleID = item.ModuleInstanceID.ToString();
                    userControlX.Title = item.Title;
                    userControlX.Params = item.Params;
                    userControlX.ShowHide = item.IsActive;
                    userControlX.State = item.State;
                    PlaceHolderLeft.Controls.Add(userControlX);
                }
            }
            rptItems.DataSource = _thongBao.Table.OrderByDescending(c => c.GhimThongBao).Take(10);
            rptItems.DataBind();

            rptNewsItems.DataSource = _serviceTinTuc.Table.OrderByDescending(c => c.IDTinTuc).Take(5);
            rptNewsItems.DataBind();

            Repeater1.DataSource = _serviceTinTuc.Table.OrderByDescending(c => c.IDTinTuc).Take(1);
            Repeater1.DataBind();
        }
    }
}